<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>call</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        /* 
        fn.call(thisObj, 函数的参数...)
            调用函数，将函数中的this转移为第一个接受的参数
            如果参数无法识别为对象，那么默认为全局对象
        */

        var uname = "window";

        function sayName(status, word){
            console.log(this.uname + status + " said: " + word);
        }

        var obj = {
            uname: "object"
        }

        sayName("激动地","hello"); // window 激动地 said hello
        sayName.call(obj, "伤心的", "world"); // object


        sayName.call(null, "伤心的", "world"); // window
        sayName.call(123, "伤心的", "world"); // undefined

        console.log(new Number(123));
        console.log(new String('hello'));
        console.log(new Boolean(true));
    </script>
</body>
</html>